import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/pages/domain/interest_item.dart';

/// 用户管理相关
class ReqUser {
  final Dio _dio;

  ReqUser(this._dio);

  /// 注册
  Future<Response> register({
    /// 手机号
    @required String phoneNumber,

    /// 密码
    @required String passwd,

    /// 短信验证码
    @required String message,
  }) {
    return _dio.post('/user/registe', queryParameters: {
      "phoneNumber": phoneNumber,
      "message": message,
      "type": "1", // 个人
      "passwd": '$passwd',
      "confirm": '$passwd',
    });
  }

//   phoneNumber: 15501145301
// vcode: mp274
// message: 202000
// passwd: love1234
// confirm: love1234
// shareNum:
// type: 1

  /// 密码登录
  Future<Response> passwordLogin({
    /// 手机号
    @required phoneNumber,

    /// 密码
    @required String passwd,
  }) {
    return _dio.post('/user/login', data: {
      "phoneNumber": '$phoneNumber',
      "passwd": '$passwd',
    });
  }

  /// 发送验证码
  Future<Response> sendMessage({
    /// 手机号
    @required telephoneNumber,

    /// 密码
    String captcha,
  }) {
    return _dio.post('/user/sendMessage', data: {
      "telephoneNumber": '$telephoneNumber',
      // "captcha": '$captcha',
    });
  }

  /// 获取兴趣栏目
  Future<Response> interest() {
    return _dio.get('/pcategory/list');
  }

  /// 添加兴趣栏目
  Future<Response> addTag({
    /// 标签列表
    @required List<InterestItem> tagList,
  }) {
    print('标签列表 $tagList');
    return _dio.post('/user/addTag', data: {"tag_ids": tagList ?? []});
  }

  /// 获取用户详情
  Future<Response> detail() {
    return _dio.post('/user/detail');
  }

  /// 查看用户资产
  Future<Response> amount({@required String token}) {
    return _dio.post('/user/amount');
  }

  /// 获取我的标签
  Future<Response> myTags() {
    return _dio.get('/user/tags');
  }

  // 添加用户标签
  Future<Response> addUserTag({
    /// 标签列表
    @required List<String> tagIds,
  }) {
    print('标签列表 $tagIds');
    return _dio.post('/user/addUserTag', data: {"tag_labels": tagIds ?? []});
  }

  /// 获取所有标签列表
  Future<Response> allTags() {
    return _dio.get('/pcategory/list');
  }

  //
  Future<Response> delTag({@required String tagName}) {
    return _dio.post('/user/delTag', data: {"label": '$tagName'});
  }

  /// 获取我的收藏
  Future<Response> reqMyCollect() {
    return _dio.get('/user/collect_list');
  }
}
